﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using libDAL;
using System.Data;
using System.Windows.Forms;
using libCommonTools.BUS;
using libAddressBook.BUS;
using System.Data.SqlClient;
using libInventory.dbml;
using libModClassVB.libModClassVB.Classes;
using Telerik.WinControls.Data;
using Telerik.WinControls.UI;
using Telerik.WinControls.RichTextBox;
using Telerik.WinControls.RichTextBox.Model;

namespace libInventory.BUS
{
     sealed class clsBUSGRN : IDisposable 
    {
         private cls_DAL _DAL;
         private cls_DAL _DALEnterprice;
         private tfCargoRecDataContext _DALtfCargoRec;
         private tfcargorecinsDataContext _DALtfCargoRecIns;

         private string strTempConStrgrn = @"Data Source=193.9.200.92\SERVERARCHIE;Initial Catalog=ESB_FMSTransactions;User ID=abc;Password=1234";
         private string strTempConEnterprc = @"Data Source=193.9.200.92\SERVERARCHIE;Initial Catalog=ESB_Enterprise;User ID=abc;Password=1234";
                
         private DataSet dsGRNMain;
         private DataSet dsGenMeasurement;
         private DataSet dsShipperMeasurement;
         private DataSet dsShipperInvoice;
         

         private DataTable dtShipper;
         private DataTable dtConsignee;
          
         private DataRow[] drShipperAddress = {};
         private DataRow[] drConsigneeAddress = {};
        
         private string strGRNNo = string.Empty;
         private DataRow[] drGRNMain = { };
         private DataRow[] drGenMeasurement = { };
         private DataRow[] drShipperMeasurement = { };
         private DataRow[] drShipperInvoice = { };
         private string strConsigneeID = string.Empty;
         private string strShipperID = string.Empty;

         public string getset_ShipperID
         {
            get
            {
                return strShipperID ;
            }
             set
             {
                 strShipperID = value;
             }

         }

         public string getset_ConsigneeID
         {
             get
             {
                 return strConsigneeID;
             }
             set
             {
                 strConsigneeID = value;             
             }
         }

         public cls_DAL get_DAL_Enterprise
         {
             get
             {
                 return _DALEnterprice;
             }
         }

         public cls_DAL get_DAL_Transactions
         {
             get
             {
                return _DAL;
             }
         }

        public string getset_GRNNo
        {
            get
            {
                return this.strGRNNo.Trim();
            }
            set
            {
                this.strGRNNo = value;
            }
        }

        public clsBUSGRN()
        {
            try
            {
                _DAL = new cls_DAL(strTempConStrgrn);
                _DALEnterprice = new cls_DAL(strTempConEnterprc);
                _DALtfCargoRec = new tfCargoRecDataContext(strTempConStrgrn);
                _DALtfCargoRecIns = new tfcargorecinsDataContext(strTempConStrgrn);
                
                Queries = new strctQueries();
                set_InstantiateDataTableAndSets();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " clsBUSGRN"); 
            }
        }

        public DataRow[] get_ShipperCompanyDetails(string strCompanyID)
        {
            DataRow[] dr = {};
            using (clsUsersMainBUSInterface _CompanyDetails = new clsUsersMainBUSInterface())
            {
               if(_CompanyDetails.set_CompanyDetails(strCompanyID, string.Empty) == true)
               {
                   dtShipper = _CompanyDetails.get_AllCompany;
                   dr = dtShipper.Select();
               }
            }
            return dr;
        }

        public DataRow[] get_ConsigneeCompanyDetails(string strCompanyID)
        {
            DataRow[] dr = { };
            using (clsUsersMainBUSInterface _CompanyDetails = new clsUsersMainBUSInterface())
            {
                if (_CompanyDetails.set_CompanyDetails(strCompanyID, string.Empty) == true)
                {
                    dtConsignee = _CompanyDetails.get_AllCompany;
                    dr = dtConsignee.Select();
                }
            }
            return dr;
        }


        public DataRow[] get_ShipperAddress
        {
            get
            {
                return this.drShipperAddress;
            }
        }

        public DataRow[] get_ConsigneeAddress
        {
            get
            {
                return this.drConsigneeAddress;
            }
        }

        public DataRow[] get_ShipperConsigneeAddress(string strCompanyID,string strShipperOrConsignee)
        {
            DataRow[] drAddress = { };
            try
            {
                if (strShipperOrConsignee.Trim().ToLower() == "shipper")
                {
                    this.drShipperAddress = _DAL.get_TableDetail(Queries.get_QueryCompanyDetails(strCompanyID)).Select();
                    drAddress = this.drShipperAddress;
                }
                else if (strShipperOrConsignee.Trim().ToLower() == "consignee")
                {
                    this.drConsigneeAddress = _DAL.get_TableDetail(Queries.get_QueryCompanyDetails(strCompanyID)).Select();
                    drAddress = this.drConsigneeAddress;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_ShipperConsigneeAddress"); 
            }
            return drAddress;
        }

        private void set_InstantiateDataTableAndSets()
        {
            dsGRNMain = new DataSet();
            dsGenMeasurement = new DataSet();
            dsShipperMeasurement = new DataSet();
            dsShipperInvoice = new DataSet();

            dtConsignee = new DataTable();
            dtShipper = new DataTable();
        }

        public string get_CodeName(string strcountrycitycompanystateareaport, string strID)
        {
            string strName = string.Empty;
            try
            {
                using (clsCommonFunctions function = new clsCommonFunctions())
                {
                    strName = function.get_CodeName(strcountrycitycompanystateareaport, strID, _DALEnterprice);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_CodeName"); 
            }
            return strName;
        }

         private struct strctQueries
         {

             private string get_Clause(string strGRNNo)
             {
                 string strClause = string.Empty;
                 if (strGRNNo != string.Empty)
                 {
                     strClause = "WHERE LTRIM(RTRIM(connoteno)) = '" + strGRNNo + "'";
                 }

                 return strClause;
             }

             private string get_Top(string strGRNNo)
             {
                 string strTop = string.Empty;
                 if (strGRNNo == string.Empty)
                 {
                     strTop = " TOP (0) ";
                 }
                 return strTop;
             }

             public string get_QueryGRNConnoteno(string strGRNNo)
             {
                 string strQuery = string.Empty;
                 try
                 {
                     strQuery = "SELECT " + get_Top(strGRNNo) + " connoteno, temconnoteno, orderno, jobfileno, connotedate, connotetime, vehplano, shipid, shipline1, shipline2, shipline3, shipline4, shipline5, conid, conline1, " +
                                " conline2, conline3, conline4, conline5, portid, tosales, instype, dtduntil, speins, issby, schcode, trastacode, startjob, optcode, appby, apprem, oldstoapp, oldstorea, " +
                                "shipinv, shipdo, shipinvno, shipdono, totwei, totqty, stickno, totcbm, grntypecode, bill, shipstatecode, shipcitycode, shippostcode, shiptelpre, shiptelno, shipfaxpre, " +
                                "shipfaxno, constatecode, concitycode, conpostcode, contelpre, contelno, confaxpre, confaxno, totloadqty, totbalance, refno, loadwei, loadcbm, meno, recby, onhold, " +
                                "onholddate, termver, termverby, meaver, meaverby, byshipmea, shipcbm, shipwei, shipqty, insvalue, insvaluef, byshipins, nbl, obl, saltercode, billremarks, pman, " +
                                "pcn, pinv, byci, termverdate, intvehicle, vehtrip, cancelby, cancelrea, speinsport, releaseby, releasedate, releaserea, billbyfcl, cashbill, comid, billagent, billbranch, " +
                                "bsaltercode, bbill, hakgerakanby, meaverdate, conareacode, shipareacode, cusdec, cusdecby, cusdecdate, vehtripdate, grnVerified, grnVerifiedBy " +
                                "FROM tfcargorec " + get_Clause(strGRNNo);
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message + " get_QueryGRNConnoteno"); 
                 }
                    return strQuery;
             }

             public string get_QueryCompanyDetails(string strCompanyID)
             {
                 return "SELECT comid, comregno, comname, addline1, addline2, addline3, addline4, areacode, " +
                        "citycode, stacode, poscode, coucode, contact, " +
                        "telpre, telno, faxpre, faxno, conope " +
                        "FROM mfcompany " +
                        "WHERE ltrim(rtrim(comid)) = '" + strCompanyID.Trim() + "'";
             }

             public string get_QueryCheckWithGLAccount(string strCompanyID)
             {
                 return "SELECT glno, comid from mfcompany " +
                        "WHERE comid = '" + strCompanyID + "'";
             }

             public string get_QueryGRNGeneralMeasurement(string strGRNNo)
             {
                 string strQuery = string.Empty;
                 try
                 {
                     strQuery = "SELECT " + get_Top(strGRNNo) + " connoteno, temconnoteno, orderno, jobfileno, cargocode, cargodes, estlength, estwidth, estheight, estcbm, " +
                                "estweight, estqty, actlength, actwidth, actheight, actcbm, actweight, actqty, loadqty, balance, uomcode, lightheavy, " +
                                "marks, dangood, shipref, locid, trastacoded, fraitem, staid, stickno, tfcargorecdID " +
                                "FROM tfcargorecd " + get_Clause(strGRNNo);       
                 }
                 catch (Exception ex)
                 { 
                    MessageBox.Show (ex.Message +  ""); 
                 }
                 return strQuery;
             }

             public string get_QueryGRNShipperMeasurement(string strGRNNo)
             {
                 string strQuery = string.Empty;
                
                 try
                 {
                     strQuery = "SELECT " + get_Top(strGRNNo) + " cargorecdsID, connoteno, itemcode, itemdes, uomcode, actlength, actwidth, actheight, actqty, actcbm, actweight, unitcbm " +
                                "FROM   tfcargorecds " + get_Clause(strGRNNo);       
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message + " get_QueryGRNShipperMeasurement"); 
                 }
                 return strQuery;
             }

             public string get_QueryShipperInvoice(string strGRNNo)
             {
                 return "SELECT  connoteno, invno, insvalue, insvaluef, CgneeID, DONo, DOQty, " +
                        "btransrefno, btripno, btripdate, bdocretdate, bdeldate, bremarks,tfcargorecinsID " +
                        "FROM tfcargorecins " + get_Clause(strGRNNo);
             }
         }

         strctQueries Queries;

         public DataRow[] getset_ShipperInvoice
         {
             get
             {
                 return drShipperInvoice;
             }
             set
             {
                 drShipperInvoice = value;
             }
         }

         public DataRow[] getset_ShipperMeasurement
         {
             get
             {
                 return drShipperMeasurement; 
             }
             set
             {
                 drShipperMeasurement = value;
             }
         }

         public DataRow[] getset_GenMeasurement
         {
             get
             {
                 return drGenMeasurement;
             }
             set
             {
                 drGenMeasurement = value;
             }
         }

         public DataRow[] getset_GRNMainDetails
         {
             get
             {
                 return drGRNMain;
             }
             set
             {
                 drGRNMain = value;
             }
         }

         private void set_InitializeToZeroDataRow(ref DataRow[] drInitializer)
         {
             DataTable dt = new DataTable();
            drInitializer = dt.Select();
         }

         public bool set_ShipperMeasurment()
         {
             bool bolStatus = false;
             try
             {
                 dsShipperMeasurement = new DataSet();
                 
                 if (_DAL.set_DataWCardinality_ds(Queries.get_QueryGRNShipperMeasurement(getset_GRNNo), ref dsShipperMeasurement, "ShipperMeasurement-2") == true)
                 {
                     //Prepare Datarow for editing/altering etc.
                     if (getset_GRNNo.Trim() != string.Empty)
                     {
                         drShipperMeasurement = dsShipperMeasurement.Tables["ShipperMeasurement-2"].Select("connoteno = '" + getset_GRNNo + "'");
                     }
                     else
                     {
                         drShipperMeasurement = dsShipperMeasurement.Tables["ShipperMeasurement-2"].Select();
                     }
                 }
                 bolStatus = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_ShipperMeasurment");
             }

             return bolStatus;
         }

         public bool set_UpdateShipperInvoice(DataTable dtSource)
         {
             bool bolStatus = false;
             try
             {

             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_UpdateShipperInvoice"); 
             }

             return bolStatus;
         }

         private bool get_CheckShipperInvice(string strtfcargorecinsID)
         {
             bool bolStatus = false;
             try
             {
                 DataRow[] drCheck = {};
                 drCheck = dsShipperInvoice.Tables["ShipperInvoice-3"].Select("tfcargorecinsID = '" + strtfcargorecinsID + "'");
                 if (drCheck.Length > 0)
                 {
                     bolStatus = true;
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " get_CheckShipperInvice"); 
             }
             return bolStatus;
         }

         public bool set_UpdateShipperInvoice()
         {
             bool bolStatus = false;
             try
             {
                // dsShipperInvoice.Tables["ShipperInvoice-3"].Select();
                 bolStatus = _DAL.set_updateBatch(ref dsShipperInvoice, "ShipperInvoice-3");
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_UpdateShipperInvoice");
             }
             return bolStatus;
         }

         //no input in the standard fields for traceability
         public bool set_TransferShipperInvoice(RadGridView dgvSource)
         {
             bool bolStatus = false;
             try
             {
                 DataRow[] drCheck = {};
                 for (int intRow = 0; intRow < dgvSource.Rows.Count; intRow++)
                 {
                     drCheck = dsShipperInvoice.Tables["ShipperInvoice-3"].Select("tfcargorecinsID = '" + clsGenFunction.get_checkStringNull (dgvSource.Rows[intRow].Cells["tfcargorecinsID"].Value) + "'");
                    if (drCheck.Length > 0)
                    {
                        for (int intCol =0 ; intCol < dgvSource.Columns.Count; intCol++)
                        {
                            if (dgvSource.Rows[intRow].Cells[intCol].Value != null)
                            {
                                drCheck[0][dgvSource.Columns[intCol].Name] = dgvSource.Rows[intRow].Cells[dgvSource.Columns[intCol].Name].Value;
                            }
                        }
                    }
                    else
                    {
                        DataRow drInsert = null;
                        for (int intCol =0 ; intCol < dgvSource.Columns.Count; intCol++)
                        {
                            drInsert = dsShipperInvoice.Tables["ShipperInvoice-3"].NewRow();
                            if (dgvSource.Rows[intRow].Cells[intCol].Value != null)
                            {
                                drInsert[dgvSource.Columns[intCol].Name] = dgvSource.Rows[intRow].Cells[dgvSource.Columns[intCol].Name].Value;
                            }

                            if (dgvSource.Columns[intCol].Name == "tfcargorecinsID")
                            {
                                drInsert[dgvSource.Columns[intCol].Name] = getset_GRNNo + "-" + drInsert[0] + "-" + drInsert[1];
                            }
                        }

                        drCheck[intRow]["tfcargorecinsID"] = getset_GRNNo + "-" + drCheck[intRow]["invno"] + "-" + drCheck[intRow]["insvaluef"] + "-"+ drCheck[intRow]["DONo"] + "-"+ clsGenFunction.get_GenKeyNEWID(_DAL).Substring (0,7);
                        drCheck[intRow]["connoteno"] = getset_GRNNo;
                        dsShipperInvoice.Tables["ShipperInvoice-3"].Rows.Add(drInsert);
                    }
                 }
                 bolStatus = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_TransferShipperInvoice"); 
             }

             return bolStatus;
         }

         //no input in the standard fields for traceability
         public bool set_TransferGeneralMeasurement(RadGridView dgvGenMeasurement)
         {
             bool bolStatus = false;
             try
             {
                 DataRow[] drCheck = {};

                 for (int intRow = 0; intRow < dgvGenMeasurement.Rows.Count; intRow++)
                 {
                     drCheck = dsGenMeasurement.Tables["GenMeasurement-1"].Select("tfcargorecdID = '" + clsGenFunction.get_checkStringNull(dgvGenMeasurement.Rows[intRow].Cells["tfcargorecdID"].Value) + "'");
                     if (drCheck.Length > 0)
                     {
                         for (int intCol = 0; intCol < dgvGenMeasurement.Columns.Count; intCol++)
                         {
                             if (dgvGenMeasurement.Rows[intRow].Cells[intCol].Value != null)
                             {
                                 drCheck[0][dgvGenMeasurement.Columns[intCol].Name] =dgvGenMeasurement.Rows[intRow].Cells[dgvGenMeasurement.Columns[intCol].Name].Value;
                             }
                         }
                     }
                     else
                     {
                         DataRow drInsert = null;
                         for (int intCol = 0; intCol < dgvGenMeasurement.Columns.Count; intCol++)
                         {
                             drInsert = dsGenMeasurement.Tables["GenMeasurement-1"].NewRow();
                             if (dgvGenMeasurement.Rows[intRow].Cells[intCol].Value != null)
                             {
                                 drInsert[dgvGenMeasurement.Columns[intCol].Name] = dgvGenMeasurement.Rows[intRow].Cells[dgvGenMeasurement.Columns[intCol].Name].Value;
                             }
                         }
                         drInsert["tfcargorecdID"] = getset_GRNNo + "-" + drInsert["invno"] + "-" + clsGenFunction.get_GenKeyNEWID(_DAL).Substring(0,7);
                         dsGenMeasurement.Tables["GenMeasurement-1"].Rows.Add(drInsert);
                     }
                 }
                 bolStatus = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_TransferGeneralMeasurement");
             }
             return bolStatus;
         }

         public bool set_LoadShipperInvoice()
         {
             bool bolStatus = false;
             try
             {
                 dsShipperInvoice  = new DataSet();
                 if (_DAL.set_DataWCardinality_ds(Queries.get_QueryShipperInvoice(getset_GRNNo), ref dsShipperInvoice, "ShipperInvoice-3") == true)
                 {
                     //Prepare Datarow for editing/altering etc.
                     if (getset_GRNNo.Trim() != string.Empty)
                     {
                         drShipperInvoice = dsShipperInvoice.Tables["ShipperInvoice-3"].Select("connoteno = '" + getset_GRNNo + "'");
                     }
                     else
                     {
                         drShipperInvoice = dsShipperInvoice.Tables["ShipperInvoice-3"].Select();
                     }
                 }
                 bolStatus = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_ShipperInvoice");
             }
             return bolStatus;
         }

         public bool set_GeneralMeasurment()
         {
             bool bolStatus = false;
             try
             {
                 dsGenMeasurement = new DataSet();
                 if (_DAL.set_DataWCardinality_ds(Queries.get_QueryGRNGeneralMeasurement(getset_GRNNo), ref dsGenMeasurement, "GenMeasurement-1") == true)
                 {
                     //Prepare Datarow for editing/altering etc.
                     if (getset_GRNNo.Trim() != string.Empty)
                     {
                         drGenMeasurement = dsGenMeasurement.Tables["GenMeasurement-1"].Select("connoteno = '" + getset_GRNNo + "'");
                     }
                     else
                     {
                         drGenMeasurement = dsGenMeasurement.Tables["GenMeasurement-1"].Select();
                     }
                 }
                 bolStatus = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_GeneralMeasurment");
             }
             return bolStatus;
         }

         public bool set_GRNMain()
         {
             bool bolStatus = false;
             try
             {
                 dsGRNMain = new DataSet();
                 if (_DAL.set_DataWCardinality_ds(Queries.get_QueryGRNConnoteno(getset_GRNNo), ref dsGRNMain, "GRN-0") == true)
                 {
                     //Prepare Datarow for editing/altering etc.
                     if (getset_GRNNo.Trim() != string.Empty)
                     {
                         drGRNMain = dsGRNMain.Tables["GRN-0"].Select("connoteno = '" + getset_GRNNo + "'");
                     }
                     else
                     {
                         drGRNMain = dsGRNMain.Tables["GRN-0"].Select();
                     }
                 }
                 bolStatus = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_GRNMain");
             }
             return bolStatus;
         }

         public bool get_CheckCompanyWithGLNo(string strCompanyID)
         {
             bool bolStatus = false;
             try
             {
                 _DAL.get_CheckAnythingExists(Queries.get_QueryCheckWithGLAccount(strCompanyID));
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " get_CheckCompanyWithGLNo"); 
             }

             return bolStatus;
         }

         public void Dispose()
         {
             GC.Collect();
             //throw new NotImplementedException();
         }

         public bool set_InsertUpdateRecordsLinqTfcargorec(string strPrimaryKey, tfcargorec liqCargorec)
         {
             bool bolStatus = false;
             try
             {
                 var tx = from p in _DALtfCargoRec.tfcargorecs
                          where p.connoteno == strPrimaryKey
                          select p;

                 if (tx.Count() == 0)
                 {
                     _DALtfCargoRec.tfcargorecs.InsertOnSubmit(liqCargorec);
                     _DALtfCargoRec.SubmitChanges();
                     bolStatus = true;
                 }
                 else
                 {
                     tfcargorec cargo = _DALtfCargoRec.tfcargorecs.Single(p => p.connoteno == strPrimaryKey);
                     if (set_VerifyUpdates(liqCargorec, ref cargo) == true)
                     {
                         _DALtfCargoRec.SubmitChanges();
                         bolStatus = true;
                     }
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_InsertUpdateRecords");
             }
             return bolStatus;
         }

         private bool set_VerifyUpdates(tfcargorec liqCargorec, ref tfcargorec cargo)
         {
             bool bolStatus = false;
             try
             {
                 if (set_ConsigneeForUpdate(liqCargorec, ref cargo) == true)
                 {
                     if (set_ShipperForUpdate(liqCargorec, ref cargo) == true)
                     {
                         if (set_ShipperMeasurementTotals(liqCargorec, ref cargo) == true)
                         {
                             if (set_GeneralMeasurementTotals(liqCargorec, ref cargo) == true)
                             {
                                 if (set_GRNDateTimeVehecle(liqCargorec, ref cargo) == true)
                                 {
                                     bolStatus = true;
                                 }
                             }
                         }
                     }
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_VerifyUpdates"); 
             }
             return bolStatus;
         }

         private bool set_ShipperMeasurementTotals(tfcargorec liqCargorec, ref tfcargorec cargo)
         {
             bool bolStatus = false;
             try
             {
                 cargo.shipcbm = liqCargorec.shipcbm;
                 cargo.shipwei = liqCargorec.shipwei;
                 cargo.shipqty = liqCargorec.shipqty;
                 bolStatus = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_ShipperMeasurementTotals");
             }
             return bolStatus;
         }

         private bool set_GeneralMeasurementTotals(tfcargorec liqCargorec, ref tfcargorec cargo)
         {
             bool bolStatus = false;
             try
             {
                 cargo.totwei = liqCargorec.totwei;
                 cargo.totqty = liqCargorec.totqty;
                 cargo.totcbm = liqCargorec.totcbm;
                 bolStatus = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_GeneralMeasurementTotals");
             }
             return bolStatus;
         }

         private bool set_GRNDateTimeVehecle(tfcargorec liqCargorec, ref tfcargorec cargo)
         {
             bool bolStatus = false;
             try
             {
                 cargo.connotedate = liqCargorec.connotedate;
                 cargo.connotetime = liqCargorec.connotetime;
                 cargo.vehplano = liqCargorec.vehplano;
                 cargo.grntypecode = liqCargorec.grntypecode;
                 cargo.stickno = liqCargorec.stickno;
                 bolStatus = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_GRNDateTimeVehecle");
             }
             return bolStatus;
         }

         private bool set_ConsigneeForUpdate(tfcargorec liqCargorec, ref tfcargorec cargo)
         {
             bool bolStatus = false;
             try
             {
                 cargo.conline1 = liqCargorec.conline1;
                 cargo.conline2 = liqCargorec.conline2;
                 cargo.conline3 = liqCargorec.conline3;
                 cargo.conline4 = liqCargorec.conline4;

                 cargo.conareacode = liqCargorec.conareacode;
                 cargo.concitycode = liqCargorec.conpostcode;
                 cargo.constatecode = liqCargorec.constatecode;

                 cargo.contelno = liqCargorec.contelno;
                 cargo.contelpre = liqCargorec.contelpre;
                 cargo.confaxpre = liqCargorec.confaxpre;
                 cargo.confaxno = liqCargorec.confaxno;

                 bolStatus = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_ConsigneeForUpdate"); 
             }
             return bolStatus;
         }

         private bool set_ShipperForUpdate(tfcargorec liqCargorec, ref tfcargorec cargo)
         {
             bool bolStatus = false;
             try
             {
                 cargo.shipline1 = liqCargorec.shipline1;
                 cargo.shipline2 = liqCargorec.shipline2;
                 cargo.shipline3 = liqCargorec.shipline3;
                 cargo.shipline4 = liqCargorec.shipline4;

                 cargo.shipareacode = liqCargorec.shipareacode;
                 cargo.shippostcode = liqCargorec.shippostcode;
                 cargo.shipstatecode = liqCargorec.shipstatecode;

                 cargo.shiptelno = liqCargorec.shiptelno;
                 cargo.shiptelpre = liqCargorec.shiptelpre;
                 cargo.shipfaxpre = liqCargorec.shipfaxpre;
                 cargo.shipfaxno = liqCargorec.shipfaxno;

                 bolStatus = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message + " set_ConsigneeForUpdate");
             }
             return bolStatus;
         }
  
    }

     sealed class clsInsertInventory : IDisposable
     {
         private cls_DAL _DAL;
         private SqlCommand command;
         private tfCargoRecDataContext _DALtfCargoRec;
         private string strTempConStrgrn = @"Data Source=193.9.200.92\SERVERARCHIE;Initial Catalog=ESB_FMSTransactions;User ID=abc;Password=1234";

         ~clsInsertInventory()
         {
            // Dispose(false);
         }
         public void Dispose()
         {
            
             GC.SuppressFinalize(true);
             //throw new NotImplementedException();
         }

         public clsInsertInventory(ref cls_DAL _DALL)
         {
             this._DAL = _DALL;
             _DALtfCargoRec = new tfCargoRecDataContext(strTempConStrgrn);
         }

        
       

        
     }
}
